import { createRouter, createWebHistory } from 'vue-router'
import type { RouteRecordRaw } from 'vue-router'

export const Layout = () => import("@/layout/index.vue");


/**
 * 静态路由
 * @type {Array<Router>}
 */
export const constantRoutes: RouteRecordRaw[] = [
    // 按钮测试页面 - 用于查看自定义黄色按钮效果
    // {
    //     path: '/button-test',
    //     component: Layout,
    //     children: [
    //         {
    //             path: '',
    //             component: () => import('@/views/test/ButtonTest.vue'),
    //             name: 'ButtonTest',
    //             meta: {
    //                 title: '按钮测试',
    //                 icon: 'dashboard',
    //                 keepAlive: false,
    //                 alwaysShow: false,
    //             },
    //         }
    //     ]
    // },
    {
        path: '/redirect',
        component: Layout,
        meta: { hidden: true },
        children: [
            {
                path: '/redirect/:path(.*)',
                component: () => import('@/views/redirect/index.vue')
            }
        ]
    },
    {
        path: '/login',
        component: () => import('@/views/login/index.vue'),
        meta: { hidden: true }
    },
    {
        path: '/',
        name: '/',
        component: Layout,
        redirect: "/dashboard",
        children: [
            {
                path: "dashboard",
                component: () => import("@/views/dashboard/index.vue"),
                name: "dashboard", // 用于 keep-alive, 必须与SFC自动推导或者显示声明的组件name一致
                // https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
                meta: {
                title: "dashboard",
                icon: "dashboard",
                affix: true,
                keepAlive: true,
                alwaysShow: false,
                },
            },
            {
                path: "401",
                component: () => import("@/views/error-page/401.vue"),
                meta: { hidden: true },
            },
            {
                path: "404",
                component: () => import("@/views/error-page/404.vue"),
                meta: { hidden: true },
            },
        ]
    }
]

/**
 * 创建路由
 */
const router = createRouter({
    history: createWebHistory(), // hash 模式改为 history 模式
    routes: constantRoutes as RouteRecordRaw[],
    // 刷新时，滚动条位置还原
    scrollBehavior: () => ({ left:0, top:0 })
})

/**
 * 重置路由
 */
export function resetRouter(){
    router.replace({ path: '/login' })
}

export default router;